(function () {

    angular
        .module('gallery')
        .controller('GalleryController', [
            'galleryService', '$mdBottomSheet', '$q',
            GalleryController
        ]);

    /**
     * Gallery Controller for the Angular Material Starter App
     * @param $scope
     * @param $mdSidenav
     * @param avatarsService
     * @constructor
     */
    function GalleryController(galleryService, $mdBottomSheet, $q) {
        var self = this;
        self.arrayData = [
            /*{src: './assets/images/gallery/o1.jpg'},*/
            {src: './assets/images/gallery/b1.jpg'},
            {src: './assets/images/gallery/h1.jpg'},
            {src: './assets/images/gallery/o2.jpg'},
            {src: './assets/images/gallery/b2.jpg'},
            {src: './assets/images/gallery/b3.jpg'},
            {src: './assets/images/gallery/b4.jpg'},
            {src: './assets/images/gallery/b5.jpg'},
            {src: './assets/images/gallery/b6.jpg'}
            /*{src: './assets/images/gallery/b7.jpg'},*/
            /*{src: './assets/images/gallery/b8.jpg'}*/
            /*{src: './assets/images/gallery/o4.jpg'},
            {src: './assets/images/gallery/o3.jpg'},
            {src: './assets/images/gallery/h2.jpg'}*/
        ];
        self.content = {};
        self.showContactOptions = showContactOptions;

        galleryService
            .loadContent()
            .then(function (content) {
                self.content = content;
            });

        /**
         * Show the bottom sheet
         */
        function showContactOptions($event) {
            var user = self.selected;

            return $mdBottomSheet.show({
                templateUrl: './src/pages/gallery/view/share.html',
                controller: ['$mdBottomSheet', ContactPanelController],
                controllerAs: "cp",
                bindToController: true,
                targetEvent: $event
            }).then(function (clickedItem) {
                clickedItem && $log.debug(clickedItem.name + ' clicked!');
            });

            /**
             * Bottom Sheet controller for the Avatar Actions
             */
            function ContactPanelController($mdBottomSheet) {
                this.user = user;
                this.actions = [
                    {name: 'Phone', icon: 'phone', icon_url: 'assets/svg/phone.svg'},
                    {name: 'Twitter', icon: 'twitter', icon_url: 'assets/svg/twitter.svg'},
                    {name: 'Google+', icon: 'google_plus', icon_url: 'assets/svg/google_plus.svg'},
                    {name: 'Hangout', icon: 'hangouts', icon_url: 'assets/svg/hangouts.svg'}
                ];
                this.submitContact = function (action) {
                    $mdBottomSheet.hide(action);
                };
            }
        }
    }
})();
